const ZipWebpackPlugin = require('zip-webpack-plugin')
const path = require('path')

const resolve = dir => path.join(__dirname, dir)

module.exports = {
  publicPath: '',
  outputDir: 'dist',
  lintOnSave: false,
  runtimeCompiler: true,
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      const domain = 'vix-template-v4'
      // 为生产环境配置...
      // https://github.com/erikdesjardins/zip-webpack-plugin
      const plugins = [
        new ZipWebpackPlugin({
          path: path.join(__dirname, './'),
          filename: `${domain}.zip`,
          pathPrefix: `${domain}`
        })
      ]
      config.plugins = [...config.plugins, ...plugins]
    }
  },
  chainWebpack: config => {
    config.resolve.symlinks(false)
    config.resolve.alias
      .set('@', resolve('src'))
      .set('@C', resolve('src/components'))
      .set('@V', resolve('src/views'))
      .set('@assets', resolve('src/assets'))
      .set('@api', resolve('src/api'))
      .set('@libs', resolve('src/libs'))
  },
  productionSourceMap: process.env.NODE_ENV !== 'production',
  transpileDependencies: ['@bairong/vix'],
  devServer: {
    port: 8899,
    proxy: {
      '/api': {
        target: 'https://example.100credit.com/',
        secure: false
      }
    }
  }
}
